<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>delete</title>
    <link rel="icon" href="../images/logo.ico">
    <style>
        body {
            overflow: hidden;
            background-color: #F2D9E6;
        }

        form {
            width: 400px;
            margin: 200px auto;
            border: 1px solid #000;
            padding: 20px;
            text-align: center;
        }

        form div {
            margin: 20px auto;
        }

        form label {
            width: 100px;
            display: inline-block;
            text-align: right;
        }

        .btn {
            padding: 5px 25px;
        }

        h2>a {
            font-size: 14px;
            /* vertical-align: bottom; */
        }
        input:not([type=reset]){
            color: red;
        }
    </style>
</head>

<body>
    <form id="register" >
        <h2><span style="color: red;">注销</span>
            <a href="./reister.html">注册</a>
            <a href="./login.html">登录</a>
        </h2>
        <div>
            <label for="username">
                账号:
            </label>
            <input type="text" id="username" name="username">
        </div>
        <div>
            <label for="password">密码:</label>
            <input type="password" id="password" name="password">
        </div>
        <div>
            <label for="rePassword">确认密码:</label>
            <input type="password" id="rePassword" name="rePassword">
        </div>
        <div>
            <input class="btn" type="submit" value="注销" id="register-btn" style="color: red;">
            <input class="btn" type="reset" value="重置">
        </div>
    </form>
</body>
<script src="../js/jquery-3.3.1.js"></script>
<script>
    var submitBtn = document.getElementById('register-btn');
    submitBtn.onclick = function (e) {
        e.preventDefault();
        var it=confirm("确定删除用户吗？");
        if (!it) {
            console.log("已取消");
            return;
        }
        var form = document.getElementById('register');
        var username = form.username.value;
        var password = form.password.value;
        var rePassword = form.rePassword.value;
        if (username && password && rePassword) {
            if (password == rePassword) {
                var data = {
                    username:username,
                    password:password,
                }
                $.ajax({
                    type: "POST",
                    data:data,
                    url: "../php/delet.php",
                    success: function (res) {
                        if (res.status){
                            alert("删除成功");
                            location.href="login.html"
                        }else {
                            alert(res.msg);
                        }
                    },
                    error: function (res) {
                        console.warn(res);
                        alert("请求失败！");
                    }
                })
            } else {
                alert("密码前后不一致");
            }
        } else {
            alert("请完善信息！");
        }
    }
</script>

</html>